package data;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * User: Vladimir
 * Date: 13.01.13 Time: 13:41
 */
public class ItemData {
    public String brand;
    public String model;
    public String article;
    public String name;
    public String engname;
    public String url;
    public int price;
    public int oldPrice;
    public int count;
    public String desc;
    public String shortdesc;
    public String sort;
    public String title;
    public String metadesc;
    public String metakey;
    public List<String> photos;
    public List<String> models;
    public List<ItemData> modelsData;
    public Map<String, String> props = new HashMap<String, String>();
    public boolean category = false;
    public boolean popular = true;
    public Orig original;

    public static final String SEPARATOR = "\t";

    @Override
    public String toString() {
        StringBuilder pics = new StringBuilder();
        for (String photo : photos) {
            pics.append(SEPARATOR).append(photo);
        }
        pics.delete(0, 0);
        String priceStr = category ? SEPARATOR + SEPARATOR + SEPARATOR : price + SEPARATOR + oldPrice + SEPARATOR + count + SEPARATOR;
        return article + SEPARATOR +
                engname + SEPARATOR +
                name + SEPARATOR +
                url + SEPARATOR +
                priceStr +
                desc + SEPARATOR +
                shortdesc + SEPARATOR +
                sort + SEPARATOR +
                title + SEPARATOR +
                metakey + SEPARATOR +
                metadesc + SEPARATOR +
                pics;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        ItemData itemData = (ItemData) o;

        if (article != null ? !article.equals(itemData.article) : itemData.article != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        return article != null ? article.hashCode() : 0;
    }

    public ItemData getCopy() {
        ItemData cloneItem = new ItemData();
        cloneItem.brand = this.brand;
        cloneItem.engname = this.engname;
        cloneItem.name = this.name;
        cloneItem.model = this.model;
        cloneItem.props = this.props;
        cloneItem.article = this.article;
        cloneItem.category = this.category;
        cloneItem.count = this.count;
        cloneItem.price = this.price;
        cloneItem.oldPrice = this.oldPrice;
        cloneItem.desc = this.desc;
        cloneItem.metadesc = this.metadesc;
        cloneItem.metakey = this.metakey;
        cloneItem.photos = this.photos;
        cloneItem.url = this.url;
        cloneItem.title = this.title;
        cloneItem.shortdesc = this.shortdesc;
        cloneItem.sort = this.sort;
        cloneItem.original = this.original;
        cloneItem.popular = this.popular;
        return cloneItem;
    }
}

enum Orig {
    ORIGINAL, NOT_ORIGINAL, NOT_SET
}